<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>浏览器</title>

    <link rel="stylesheet" type="text/css" href="../../css/api.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/yzl.css"/>

    <style>
        .browser-close {
            display: inline-block;
            position: absolute;
            width: 30px;
            height: 45px;
            top: 15px;
            left: 40px;
            background-size: 17px 17px;
            background-position: left;
            background-repeat:no-repeat;
        }

        .browser-close.big {
            background-image: url(../../image/big/btn_close_white.png);
        }

        .browser-close.small {
            background-image: url(../../image/small/btn_close_white.png);
        }

        .browser-title {
            margin: 0 60px;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }
    </style>

</head>
<!-- <div class="header" id="app" v-cloak>
    <div id="back" class="back" style="width:30px;" :class="BSImg" onclick="back()"></div>
    <div  v-myclick="backapp" style="float:right;margin-right:10px;margin-top:5px;font-size:14px" >返回app</div>
    <div id="browser-close" class="browser-close" :class="BSImg" v-show="changeTime >= 2" onclick="closeWin()"></div>
    <div  class="title browser-title">{{title}}</div>
</div> -->
<body>
</body>
<script src="../../script/api.js"></script>
<script src="../../script/vue.js"></script>
<script src="../../script/app.js"></script>
<script src="../../script/common.js"></script>
<script src="../../script/url.js"></script>
<script>

    var webBrowser,
        url,
        vm;
    var state =1;

    apiready = function () {
        setBSImg();
        var back = document.getElementById('back');
        // var browserClose = document.getElementById('browser-close');
        // setTapmode([back, browserClose]);
        webBrowser = api.require('webViewModule');
        MNActionButton = api.require('PIActionButton');
        url = api.pageParam.url;

        // if(!url){
          url = bpshost+"tb.html?pid=zdsj&uid="+getPrefs('member_id')+"&usertoken="+getPrefs('token');
        // }

        initApp();
        openWeb();
        addListeners();

        api.parseTapmode();
    };

    function initApp() {
        vm = new Vue({
            el: '#app',
            data: {
                changeTime: 0,
                BSImg: {
                    big: Vue.BSImg == 'big',
                    small: Vue.BSImg == 'small'
                },
                title: '正在加载中...',
            },
            methods: {
              backapp:function(){
                api.closeWin();


              }
    },
        });
    }

    function back() {
        webBrowser.historyBack(function (ret) {
            if (!ret.status) {
                closeWin();
            }
        });
    }

    function openWeb() {
        var forbid_urlschemes = null;
        if (getPrefs('forbid_urlschemes')) {
            forbid_urlschemes = JSON.parse(getPrefs('forbid_urlschemes'));
        }
        webBrowser.openView({
            url: url,
            frameName:'shop',
            fixedOn : 'shop',
            name:'shopview',
            rect: {
                x: 0,
                y: 0,
                w: 'auto',
                h: api.winHeight-110
            },
            forbid_urlschemes: forbid_urlschemes || ["tbopen", "tmall", "taobao", "openapp.jdmoble","pinduoduo"],
        }, function (ret, err) {
          if(ret.state!=11){
            console.log(JSON.stringify(ret));
          }
          // webBrowser.loadScript({    script: 'api.alert({msg:"测试"})'});

            switch (ret.state) {            //加载状态，数字类型，取值范围：0-开始加载；1-加载进度发生变化；2-结束加载；3-title发生变化；4-url发生变化
                case 0:
                    break;
                case 1:
                    break;
                case 2:
                if(ret.url.indexOf('tb.html?pid=')>-1){
                  api.sendEvent({
                    name: 'pageindex',
                    extra: {
                        status: true,
                    }
                });
              }else{
                api.sendEvent({
                  name: 'pageindex',
                  extra: {
                      status: false,
                  }
              });
              }

                    vm.changeTime++;
                    break;
                case 3:
                    vm.title = ret.title;
                    break;
                case 4:
                    break;
                case 5:
                    break;
                case 6:
                    break;
                default:
                    break;
            }
        })
    }
    function addListeners(){
      api.addEventListener({
          name: 'closeshop'
      }, function (ret, err) {
        // webBrowser.closeView();
        api.closeWin({
            name: 'shop'
        });

      });
      api.addEventListener({
        name: 'shopback'
    }, function () {
      webBrowser.historyBack({
        frameName:'shop',
        name:'shopview',
        fixedOn : 'shop',
      },
      function (ret, err) {
      }
  );
});
    }
</script>
</html>
